import { getCates } from '../../utils/api'
const state = {
    list: [],
    secondlist: []
}

const mutations = {
    changelist(state, arr) {
        state.list = arr
    },
    changesecondlist(state, arr) {
        state.secondlist = arr
    }
}

const actions = {
    reqchangelist(context) {
        getCates().then(res => {
            console.log(res.data.list[0].children);
            context.commit('changelist', res.data.list),
                context.commit('changesecondlist', res.data.list[0].children)
        })
    },
    reqsecondlist(context, index) {
        let list = context.state.list[index].children ? context.state.list[index].children : []
        context.commit('changesecondlist', list)
    }
}

const getters = {
    list(state) {
        return state.list
    },
    secondlist(state) {
        return state.secondlist
    }
}

export default {
    state,
    actions,
    mutations,
    getters,
    namespaced: true
}